package com.sm.tools;

import java.util.ArrayList;

import com.sm.bo.Course;

public class CoursManager {
	
	public static int addCourse(ArrayList<Course> coursesList, Course course){
		coursesList.add(course);
		return 1;
	}
	
	public static int removeCourse(ArrayList<Course> coursesList, String courseCode){
		Course courseR = getCourseByCode(coursesList, courseCode);
		if (courseR != null) {
			coursesList.remove(courseR);
			return 1;
		} else {
			return 0;
		}
	}
	
	private static Course getCourseByCode(ArrayList<Course> coursesList, String code){
		Course courseR = null;
		for (Course course :  coursesList) {
			if (course.getCode().equals(code))
				courseR = course;
		}
		return courseR;
	}

}
